GBML manual / Collision

One-way platforms

A floor you can jump up through and then stand on. Paint it with the One-way button, and see how the player, your own code and falling things treat it.

The idea

Think of a shelf in a platformer. You come at it from underneath and your head goes right through it. You land on top and you stand there. You walk in from the side and nothing stops you. And if you want to leave, you press down and jump, and you drop through it again.

That is a One-way square. It only stops something that is coming down onto its top.

Paint one

  1. Open the Room Editor and find Collision in the left panel.
  2. Press One-way. It sits beside Keep, under Pass, Solid and Low cover.
  3. Turn on Attribute brush and paint. A One-way square shows in its own color with a little arrow pointing up along its top edge.

Paint only the squares that should be the platform. A single row is plenty. A thick platform is fine too, because anything inside it keeps moving.

Like Solid, a One-way square takes a shape. Pick the half-height shape first and the platform's top sits 4 pixels down inside its square, so a platform does not have to sit on the 8 pixel grid.

A sloped one-way floor

A One-way floor does not have to be flat. Draw a slope or a curve in the Room Editor (under Shape in the Collision section, or from the Tile Palette), and in the little window that asks for the class pick One-way next to Pass, Solid and Low cover. The slope or curve you draw becomes a sloped shelf.

It behaves like a flat shelf, tilted:

A thin slope is easy to see: the line of its top is the only part that holds you up. Under it there is only air, so a one-way slope is a good ramp over a gap or a hill you can still jump through from underneath.

The player's tick box (below) does all of this. Your own code can ask the same thing with tile_one_way and tile_ground_y; both answer pixel by pixel, so they see the slope's real top, not the top of its square.

What the player does

The Player movement designer has a tick box, Stands on one-way platforms. It is on for a new platformer. With it on, the player:

Untick it and the player treats a One-way square as open air, so it falls straight through. Use that for something that should not stand on platforms, like a ghost.

The older ways still work: a tile flag you pick under One-way tile flag, and the One-way platforms list of objects.

What your own code does

Every ordinary collision question treats a One-way square as open: tile_solid, tile_free and move_slide all let a thing through. That is on purpose. Code you wrote before, and a thing that has no idea about platforms, never gets stuck on one.

To make your own thing stand on a platform, ask tile_one_way. It is true for a spot that is inside a One-way square. A thing is standing on a platform when the spot just under its feet is one and the spot at its feet is not:

var on_top = tile_one_way(x, box_bottom) && !tile_one_way(x, box_bottom - 1);

The second half is what lets a thing that is already inside a platform keep moving. A thing that jumped up through it, or walked in from the side, is not on top of anything.

A crate that falls and lands on a platform or on the ground:

var on_top = tile_one_way(x, box_bottom) && !tile_one_way(x, box_bottom - 1);
if (!on_top && tile_free(x, y + 1)) {
    y += 1;
}

tile_ground_y counts the top of a One-way platform as ground too, so it tells you how far a thing has to fall.

Good to know

See also: tile_one_waytile_ground_ytile_freetile_solidTile flagsSlopesOverlap and collision